home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / SHADOW_C.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  6.5 KB  |  229 lines

  1.  
  2. package sub_arctic.lib;
  3.  
  4. import sub_arctic.output.drawable;
  5. import sub_arctic.output.shadow_drawable;
  6.  
  7. import java.awt.Dimension;
  8. import java.awt.Point;
  9.  
  10. /**
  11.  * This class provides a container that draws its child subtrees with a
  12.  * shadow under them.  This is done by drawing the children twice, once 
  13.  * with a shadow_drawable object (which turns all colors gray and offsets
  14.  * the drawing slightly), then again on top normally.  Shadow_graphics objects
  15.  * have two drawing settings, expensive but accurate, and fast but inaccurate
  16.  * (in particular drawing all images as filled rectangles).  This setting can
  17.  * also be made here and defaults to fast.
  18.  *
  19.  * @see sub_arctic.output.shadow_drawable
  20.  * @author Scott Hudson
  21.  */
  22. public class shadow_caster extends base_parent_interactor {
  23.  
  24.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  25.  
  26.    /** 
  27.     * Do we do expensive but realistic drawing of shadows for images, or do 
  28.     * we just do their bounding rectangle?  Default is to be cheap about it.
  29.     */
  30.    protected boolean _expensive_draw = false;
  31.  
  32.    /** 
  33.     * Are currently doing expensive but realistic drawing shadows for images, 
  34.     * or do are we just drawing their bounding rectangle?
  35.     * @return boolean true if we are doing expensive drawing.
  36.     */
  37.    public boolean expensive_draw() {return _expensive_draw;} 
  38.  
  39.    /** 
  40.     * Set whether we draw image shadows realistically, but expensively (slow),
  41.     * or just draw their bounding rectangles (fast).
  42.     * @param boolean v the new setting (true for expensive).
  43.     */
  44.    public void set_expensive_draw(boolean v) 
  45.      {
  46.        if (v != _expensive_draw)
  47.      {
  48.            _expensive_draw = v;
  49.        damage_self(); 
  50.      }
  51.      }
  52.  
  53.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  54.  
  55.    /** 
  56.     * Full constructor.
  57.     * @param int xv     the x position of the interactor.
  58.     * @param int yv     the y position of the interactor.
  59.     * @param int wv     the width of the interactor.
  60.     * @param int hv     the height of the interactor.
  61.     * @param int shad_x the x offset of the shadow.
  62.     * @param int shad_y the y offset of the shadow.
  63.     */
  64.    public shadow_caster(int xv, int yv, int wv, int hv, int shad_x, int shad_y) 
  65. {
  66.        super(xv,yv,wv,hv);
  67.        _x_offset = shad_x;
  68.        _y_offset = shad_y;
  69.        _expensive_draw = false;
  70.      }
  71.  
  72.     //had:
  73.     //* @exception general PROPAGATED
  74.  
  75.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  76.  
  77.    /** 
  78.     * Constructor with default shadow offsets.
  79.     * @param int xv     the x position of the interactor.
  80.     * @param int yv     the y position of the interactor.
  81.     * @param int wv     the width of the interactor.
  82.     * @param int hv     the height of the interactor.
  83.     */
  84.    public shadow_caster(int xv, int yv, int wv, int hv) 
  85. {
  86.        this(xv,yv,wv,hv,
  87.           shadow_drawable.default_off_x,shadow_drawable.default_off_y);
  88.      }
  89.  
  90.     //had:
  91.     //* @exception general PROPAGATED
  92.  
  93.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  94.  
  95.    /** X offset for shadow */
  96.    protected int _x_offset;
  97.  
  98.    /** 
  99.     * X offset for shadow.
  100.     * @return int the x offset of the shadow.
  101.     */
  102.    public int x_offset() {return _x_offset;}
  103.  
  104.    /** 
  105.     * Set x offset for shadow.
  106.     * @param int xoff new x offset.
  107.     */
  108.    public void set_x_offset(int xoff) 
  109. {
  110.        /* need a redraw after this */
  111.        damage_self();
  112.  
  113.        _x_offset = xoff;
  114.      }
  115.  
  116.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  117.  
  118.    /** Y offset for shadow */
  119.    protected int _y_offset;
  120.  
  121.    /** 
  122.     * Y offset for shadow. 
  123.     * @return int the y offset of the shadow.
  124.     */
  125.    public int y_offset() {return _y_offset;}
  126.  
  127.    /** 
  128.     * Set y offset for shadow. 
  129.     * @param int yoff new y offset.
  130.     */
  131.    public void set_y_offset(int yoff) 
  132. {
  133.        /* need a redraw after this */
  134.        damage_self();
  135.  
  136.        _y_offset = yoff;
  137.      }
  138.  
  139.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  140.  
  141.    /** 
  142.     * Set offset for shadow.
  143.     * @param int xoff new x offset.
  144.     * @param int yoff new y offset.
  145.     */
  146.    public void set_offset(int xoff, int yoff) 
  147. {
  148.        /* need a redraw after this */
  149.        damage_self();
  150.  
  151.        _x_offset = xoff;
  152.        _y_offset = yoff;
  153.      }
  154.  
  155.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  156.  
  157.    /** 
  158.     * Draw self.  We draw our children twice, once in shadow offset by
  159.     * a small translation, then again in normal colors.
  160.     * @param drawable d the surface we draw on.
  161.     */
  162.    protected void draw_self_local(drawable d) 
  163. {
  164.        shadow_drawable shadow_d = new shadow_drawable(d,x_offset(),y_offset());
  165.        shadow_d.set_expensive_draw(expensive_draw());
  166.  
  167.        draw_children(shadow_d);
  168.        draw_children(d);
  169.      }
  170.  
  171.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  172.  
  173.    /** 
  174.     * Catch damage from our children and make it bigger to account for the
  175.     * shadow.
  176.     * @param Point      top_left the top-left corner of the child damage (in our
  177.     *                            coordinates).
  178.     * @param Dimension sz       the size of the damaged area.
  179.     */
  180.    public void damage_from_child(Point top_left, Dimension sz) 
  181. {
  182.     int       px, py;
  183.     Point     new_pt;
  184.         Dimension larger_sz;
  185.  
  186.         /* expand the size to include extra for the shadow */
  187.         larger_sz = new Dimension(sz.width + Math.abs(_x_offset), 
  188.                               sz.height+ Math.abs(_y_offset));  
  189.  
  190.     /* if this was negative, move top & left edges */
  191.     if (_x_offset < 0) 
  192.       px = top_left.x + _x_offset;
  193.     else
  194.       px = top_left.x;
  195.     if (_y_offset < 0) 
  196.       py = top_left.y + _y_offset;
  197.     else
  198.       py = top_left.y;
  199.     new_pt = new Point(px,py);
  200.     
  201.  
  202.     /* let the superclass do the rest */
  203.         super.damage_from_child(new_pt, larger_sz);
  204.       }
  205.  
  206.     //had:
  207.     //* @exception general PROPAGATED.
  208.  
  209.    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  210. }
  211.     
  212.  
  213. /*=========================== COPYRIGHT NOTICE ===========================
  214.  
  215. This file is part of the subArctic user interface toolkit.
  216.  
  217. Copyright (c) 1996 Scott Hudson and Ian Smith
  218. All rights reserved.
  219.  
  220. The subArctic system is freely available for most uses under the terms
  221. and conditions described in 
  222.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  223. and appearing in full in the lib/interactor.java source file.
  224.  
  225. The current release and additional information about this software can be 
  226. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  227.  
  228. ========================================================================*/
  229.